using System;
using System.Windows.Forms;

namespace demo
{
    public class TestSync
    {
        public static string ExecuteSyncTest()
        {
            string result = "开始执行环境同步测试...\n";
            
            try
            {
                // 首先检查是否需要同步
                if (EnvironmentSyncHelper.NeedSync())
                {
                    result += "检测到开发环境有更新，需要同步到生产环境\n";
                    
                    // 执行预览模式
                    result += "\n=== 预览模式 ===\n";
                    var previewOptions = new EnvironmentSyncHelper.SyncOptions
                    {
                        DryRun = true,
                        CreateBackup = false,
                        ConfirmOverwrite = false
                    };
                    
                    var previewResult = EnvironmentSyncHelper.SyncEnvironment(previewOptions);
                    result += $"预览结果: {previewResult.Success}\n";
                    result += $"处理文件数: {previewResult.ProcessedFiles.Count}\n";
                    
                    // 执行实际同步
                    result += "\n=== 执行同步 ===\n";
                    var syncOptions = new EnvironmentSyncHelper.SyncOptions
                    {
                        DryRun = false,
                        CreateBackup = true,
                        ConfirmOverwrite = false
                    };
                    
                    var syncResult = EnvironmentSyncHelper.SyncEnvironment(syncOptions);
                    result += $"同步结果: {syncResult.Success}\n";
                    result += $"处理文件数: {syncResult.ProcessedFiles.Count}\n";
                    result += $"跳过文件数: {syncResult.SkippedFiles.Count}\n";
                    result += $"错误数: {syncResult.Errors.Count}\n";
                    
                    if (syncResult.Success)
                    {
                        result += "✅ 同步成功！FormTest的改动已同步到Form1\n";
                    }
                    else
                    {
                        result += "❌ 同步失败！\n";
                        foreach (var error in syncResult.Errors)
                        {
                            result += $"错误: {error}\n";
                        }
                    }
                }
                else
                {
                    result += "开发环境和生产环境已同步，无需更新\n";
                }
            }
            catch (Exception ex)
            {
                result += $"同步测试异常: {ex.Message}\n";
            }
            
            return result;
        }
    }
}